package com.haocang.szgm.ui.home.fragment;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.haocang.commonlib.network.interfaces.InitDataOneBeanBack;
import com.haocang.commonlib.pagegrid.MyPageIndicator;
import com.haocang.commonlib.pagegrid.PageGridView;
import com.haocang.commonlib.recyclerView.BaseAdapter;
import com.haocang.szgm.R;
import com.haocang.szgm.requestcenter.DataModel;
import com.haocang.commonlib.network.interfaces.InitDataBeanBack;
import com.haocang.commonlib.network.interfaces.InitDataCallBack;
import com.haocang.szgm.ui.analysis.activity.DataAnalysisActivity;
import com.haocang.szgm.ui.event.acitvity.EventActivity;
import com.haocang.szgm.ui.floodpoint.activity.FloodPointListActivity;
import com.haocang.szgm.ui.home.activity.HomeIndexChatActivity;
import com.haocang.szgm.ui.home.activity.WeatherActivity;
import com.haocang.szgm.ui.home.adapter.HomeDataAdapter;
import com.haocang.szgm.ui.home.adapter.HomePageMenuAdapter;
import com.haocang.szgm.ui.home.adapter.HomeTaskAdapter;
import com.haocang.szgm.ui.home.adapter.PageGridViewListener;
import com.haocang.szgm.ui.home.bean.HomeDataBean;
import com.haocang.szgm.ui.home.bean.HomeMenuBean;
import com.haocang.szgm.ui.home.bean.HomeTaskBean;
import com.haocang.szgm.ui.home.bean.MsgNumberBean;
import com.haocang.szgm.ui.home.bean.RealTimeTrafficBean;
import com.haocang.szgm.ui.ht.HtProcessActivity;
import com.haocang.szgm.ui.monitor.activity.ComprehensiveActivity;
import com.haocang.szgm.ui.pipedata.activity.PipeDataActivity;
import com.haocang.szgm.ui.reason.activity.EmergencySolutionActivity;
import com.haocang.szgm.ui.report.activity.PurificationPlantDayReadActivity;
import com.haocang.szgm.ui.report.bean.PurificationPlantDayBean;
import com.haocang.szgm.ui.waterpoint.activity.WaterPointActivity;
import com.haocang.szgm.utils.bean.EarlyWarningActionBean;
import com.haocang.szgm.utils.bean.ReasonBean;
import com.haocang.szgm.utils.config.Config;
import com.haocang.szgm.utils.config.WebApi;
import com.haocang.szgm.utils.tools.CacheData;
import com.haocang.szgm.utils.tools.MyTextUtils;
import com.haocang.szgm.utils.view.ObservableScrollView;
import com.haocang.szgm.utils.view.ScrollViewListener;
import com.yzq.zxinglibrary.android.CaptureActivity;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.common.Constant;

import net.tsz.afinal.FinalBitmap;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建时间：2019/3/5
 * 编 写 人：ShenC
 * 功能描述：首页
 */
public class HomeFragment extends Fragment implements ScrollViewListener, PageGridViewListener {
    private View view;
    private Context context;

    private ImageView home_scarn;

    PageGridView pageGridView;
    MyPageIndicator pageIndicator;
    private HomePageMenuAdapter mHomePageMenuAdapter;
    private RecyclerView recyclerview_zhibiao, recyclerview_shijian, recyclerview_jsd, recyclerview_dbrw;
    private HomeDataAdapter mHomeDataAdapter_zhibiao, mHomeDataAdapter_shijian, mHomeDataAdapter_jsd;
    private HomeTaskAdapter mHomeTaskAdapter;
    private ObservableScrollView scrollview;
    private LinearLayout fl_layout, home_reason_lin;
    private ImageView lin_event_more, lin_water_more;
    private TextView app_name, tv_city, tv_reason_name, tv_reason_startdt, tv_reason_level, tv_solution_name, tv_waterpoint_num, tv_user_count, tv_car_count;

    private LinearLayout home_weather_lin;

    //天气预报
    private ImageView iv_home_weather;
    private TextView tv_home_weather_wd, tv_home_weather_memo;

    private final int REQUEST_CODE_SCAN = 1993;

    private String ls_EmergencySolutionID = "";

    Handler handler = new Handler();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_home, container, false);
        context = this.getActivity();

        initView();

        initEvent();

        RefreshReasonData();

        handler.postDelayed(runnable, 60000);

        return view;
    }


    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            try {
                handler.postDelayed(this, 60000);//首页关键指标一分钟更新一次
                RefreshRealTimeTraffic();
            } catch (Exception e) {
                e.printStackTrace();

            }
        }
    };

    @Override
    public void onResume() {
        super.onResume();
        showLocationName();
        initWeatherData();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        handler.removeCallbacks(runnable);
    }

    private void initView() {


        app_name = view.findViewById(R.id.app_name);
        tv_city = view.findViewById(R.id.tv_city);
        home_scarn = view.findViewById(R.id.home_scarn);
        fl_layout = view.findViewById(R.id.fl_layout);
        scrollview = view.findViewById(R.id.scrollview);
        pageIndicator = view.findViewById(R.id.pageindicator);
        pageGridView = view.findViewById(R.id.pagingGridView);
        recyclerview_zhibiao = view.findViewById(R.id.recyclerview_zhibiao);
        recyclerview_shijian = view.findViewById(R.id.recyclerview_shijian);
        recyclerview_jsd = view.findViewById(R.id.recyclerview_jsd);
        recyclerview_dbrw = view.findViewById(R.id.recyclerview_dbrw);
        tv_waterpoint_num = view.findViewById(R.id.tv_waterpoint_num);

        lin_event_more = view.findViewById(R.id.lin_event_more);
        lin_water_more = view.findViewById(R.id.lin_water_more);

        home_reason_lin = view.findViewById(R.id.home_reason_lin);
        tv_reason_name = view.findViewById(R.id.tv_reason_name);
        tv_reason_startdt = view.findViewById(R.id.tv_reason_startdt);
        tv_reason_level = view.findViewById(R.id.tv_reason_level);
        tv_solution_name = view.findViewById(R.id.tv_solution_name);
        tv_user_count = view.findViewById(R.id.tv_user_count);
        tv_car_count = view.findViewById(R.id.tv_car_count);

        iv_home_weather = view.findViewById(R.id.iv_home_weather);
        tv_home_weather_wd = view.findViewById(R.id.tv_home_weather_wd);
        tv_home_weather_memo = view.findViewById(R.id.tv_home_weather_memo);
        home_weather_lin = view.findViewById(R.id.home_weather_lin);

        mHomePageMenuAdapter = new HomePageMenuAdapter(HomeMenuBean.getHomeMenu(), context);
        mHomeDataAdapter_zhibiao = new HomeDataAdapter(context);
        mHomeDataAdapter_shijian = new HomeDataAdapter(context);
        mHomeDataAdapter_jsd = new HomeDataAdapter(context);
        mHomeTaskAdapter = new HomeTaskAdapter(context);
        pageGridView.setOnItemClickListener(mHomePageMenuAdapter);
        pageGridView.setAdapter(mHomePageMenuAdapter);
        pageGridView.setPageIndicator(pageIndicator);

        if (HomeMenuBean.getHomeMenu().size() > 8) {
            pageIndicator.setVisibility(View.VISIBLE);
        } else {
            pageIndicator.setVisibility(View.GONE);
        }

        scrollview.setScrollViewListener(this);
        mHomePageMenuAdapter.setPageGridViewListener(this);

        recyclerview_zhibiao.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL) {
            @Override
            public boolean canScrollVertically() {
                return false;//是否允许滑动
            }
        });
        recyclerview_shijian.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL) {
            @Override
            public boolean canScrollVertically() {
                return false;//是否允许滑动
            }
        });
        recyclerview_jsd.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL) {
            @Override
            public boolean canScrollVertically() {
                return false;//是否允许滑动
            }
        });
        recyclerview_dbrw.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL) {
            @Override
            public boolean canScrollVertically() {
                return true;//是否允许滑动
            }
        });


        recyclerview_zhibiao.setAdapter(mHomeDataAdapter_zhibiao);
        mHomeDataAdapter_zhibiao.setNewData(HomeDataBean.getHomeData_zb());

        recyclerview_shijian.setAdapter(mHomeDataAdapter_shijian);
        recyclerview_jsd.setAdapter(mHomeDataAdapter_jsd);
        recyclerview_dbrw.setAdapter(mHomeTaskAdapter);

        mHomeTaskAdapter.setNewData(HomeTaskBean.getHomeTask());


    }

    private void initEvent() {


        home_scarn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, CaptureActivity.class);
                ZxingConfig config = new ZxingConfig();
                config.setShowbottomLayout(true);//底部布局（包括闪光灯和相册）
                config.setPlayBeep(false);//是否播放提示音
                config.setShake(true);//是否震动
                config.setShowAlbum(false);//是否显示相册
                config.setShowFlashLight(true);//是否显示闪光灯
                intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);
                startActivityForResult(intent, REQUEST_CODE_SCAN);
            }
        });


        home_weather_lin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it = new Intent(context, WeatherActivity.class);
                startActivity(it);
            }
        });


        lin_event_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it = new Intent(context, EventActivity.class);
                startActivity(it);
            }
        });

        lin_water_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it = new Intent(context, WaterPointActivity.class);
                it.putExtra("TYPE", "NOW");
                startActivity(it);
            }
        });


        tv_solution_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (MyTextUtils.IsNullByString(ls_EmergencySolutionID)) {
                    ToastShow("当前无预案！");
                    return;
                }
                Intent intent = new Intent(context, EmergencySolutionActivity.class);//预案内容
                intent.putExtra("ID", ls_EmergencySolutionID);
                startActivity(intent);
            }
        });

        mHomeDataAdapter_zhibiao.setOnItemChildClickListener(new BaseAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseAdapter adapter, View v, int position) {

                HomeDataBean bean = mHomeDataAdapter_zhibiao.getItem(position);
                Intent it = new Intent(context, HomeIndexChatActivity.class);
                if (position == 9) {
                    if( bean.getData().equals("0/0")){
                        ToastShow("无数据");
                    }else {
                        it.putExtra("TYPE", "BILL");
                        it.putExtra("Data", bean.getData());
                        startActivity(it);
                    }
                } else if (position == 0 || position == 1) {

                    it.putExtra("TYPE", "ZHIBIAO");
                    startActivity(it);
                }else if (position == 2) {
//                    GetApiRequestOneMode
                    it.putExtra("TYPE", "PUBPSTATION");
                    startActivity(it);
                }else{
                    Intent it1 = new Intent(context, DataAnalysisActivity.class);
                    it1.putExtra("FromHome", false);
                    it1.putExtra("MPOINT", bean.getTagID());
                    startActivity(it1);
                }


            }
        });

        mHomeDataAdapter_shijian.setOnItemChildClickListener(new BaseAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseAdapter adapter, View v, int position) {

                Intent it = new Intent(context, HomeIndexChatActivity.class);
                it.putExtra("TYPE", "SHIJIAN");
                it.putExtra("E1", mHomeDataAdapter_shijian.getItem(1).getData().replaceAll("处", ""));
                it.putExtra("E2", mHomeDataAdapter_shijian.getItem(2).getData().replaceAll("处", ""));
                it.putExtra("E3", mHomeDataAdapter_shijian.getItem(3).getData().replaceAll("处", ""));
                startActivity(it);

            }
        });

        mHomeDataAdapter_jsd.setOnItemChildClickListener(new BaseAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseAdapter adapter, View v, int position) {

                Intent it = new Intent(context, HomeIndexChatActivity.class);
                it.putExtra("TYPE", "JSD");
                it.putExtra("W1", mHomeDataAdapter_jsd.getItem(1).getData().replaceAll("处", ""));
                it.putExtra("W2", mHomeDataAdapter_jsd.getItem(2).getData().replaceAll("处", ""));
                it.putExtra("W3", mHomeDataAdapter_jsd.getItem(3).getData().replaceAll("处", ""));
                it.putExtra("W4", mHomeDataAdapter_jsd.getItem(4).getData().replaceAll("处", ""));
                it.putExtra("W5", mHomeDataAdapter_jsd.getItem(5).getData().replaceAll("处", ""));
                startActivity(it);

            }
        });


    }


    @Override
    public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {

        if (y > 0 && y < 255) {
            fl_layout.setBackgroundColor(Color.argb(y, 0, 108, 177));
            app_name.setTextColor(Color.argb(y, 255, 255, 255));
        }
        if (y >= 255) {
            fl_layout.setBackgroundColor(Color.argb(255, 0, 108, 177));
            app_name.setTextColor(Color.argb(255, 255, 255, 255));
        }
        if (y == 0) {
            fl_layout.setBackgroundColor(Color.argb(0, 0, 108, 177));
            app_name.setTextColor(Color.argb(0, 255, 255, 255));

            fl_layout.setVisibility(View.GONE);


        } else {
            fl_layout.setVisibility(View.VISIBLE);
        }
        showLocationName();

    }

    private void showLocationName() {
        if (CacheData.LocationCity != null && !CacheData.LocationCity.equals("")) {
            String cityname = CacheData.LocationCity + CacheData.LocationDistrict;
            tv_city.setText(cityname);
        } else {
            tv_city.setText("深圳市光明区");
        }
    }

    /**
     * ===============================================
     * 创建时间：2019/3/30 17:03
     * 编 写 人：ShenC
     * 方法说明：更新面板统计数据
     * ================================================
     * 修改内容：      修改时间：      修改人：
     * ===============================================
     *///更新面板统计数据
    public void RefreshUiPageData(MsgNumberBean model) {

        List<HomeDataBean> event_list = new ArrayList<>();
        event_list.add(new HomeDataBean(model.getEvent_SUM() + "处", "全部"));
        event_list.add(new HomeDataBean(model.getEvent_S0() + "处", "未处理"));
        event_list.add(new HomeDataBean(model.getEvent_S1() + "处", "处理中"));
        event_list.add(new HomeDataBean(model.getEvent_S2() + "处", "已处理"));
        mHomeDataAdapter_shijian.setNewData(event_list);

        List<HomeDataBean> water_list = new ArrayList<>();
        water_list.add(new HomeDataBean(model.getWaterPoint_SUM() + "处", "全部"));
        water_list.add(new HomeDataBean(model.getWaterPoint_S0() + "处", "未处置"));
        water_list.add(new HomeDataBean(model.getWaterPoint_S1() + "处", "处置中"));
        water_list.add(new HomeDataBean(model.getWaterPoint_S2() + "处", "已处置"));
        water_list.add(new HomeDataBean(model.getWaterPoint_S3() + "处", "未巡查"));
        water_list.add(new HomeDataBean(model.getWaterPoint_S4() + "处", "未积水"));
        mHomeDataAdapter_jsd.setNewData(water_list);


        RefreshRealTimeTraffic();
    }


    /**===============================================
     * 创建时间：2019/10/12 17:26
     * 编 写 人：ShenC
     * 方法说明：刷新指标的值
     *================================================
     * 修改内容：      修改时间：      修改人：
     *===============================================*/
    public void RefreshRealTimeTraffic() {
        DataModel.GetApiRequestOneMode("RealTimeTrafficBean", WebApi.Api_GetRealTimeTraffic, new InitDataOneBeanBack<RealTimeTrafficBean>() {
            @Override
            public void callbak(boolean b, RealTimeTrafficBean data, String msg) {
                if(b){
                    if(data != null) {
                        List<HomeDataBean> zb_list = new ArrayList<>();
                        zb_list.add(new HomeDataBean(data.getRljjszl()==null?"-":data.getRljjszl()+"m³" ,"日累计进水量"));
                        zb_list.add(new HomeDataBean(data.getRljcszl()==null?"-":data.getRljcszl()+"m³","日累计出水量"));
//                      zb_list.add(new HomeDataBean(data.getShl()==null?"-":data.getShl()+"m³","耗损量"));
                        zb_list.add(new HomeDataBean((data.getKbqk()==null?"-":data.getKbqk())+"/6","泵站开泵情况"));
                        zb_list.add(new HomeDataBean(data.getJscncyw()==null?"-":data.getJscncyw()+"m" ,"进水池液位(南池)","000003236"));
                        zb_list.add(new HomeDataBean(data.getJscbcyw()==null?"-":data.getJscbcyw()+"m" ,"进水池液位(北池)","000003237"));
                        zb_list.add(new HomeDataBean(data.getXhsyza()==null?"-":data.getXhsyza()+"m" ,"箱涵上游(左岸)","SS0000009"));
                        zb_list.add(new HomeDataBean(data.getXhsyya()==null?"-":data.getXhsyya()+"m" ,"箱涵上游(右岸)","SS0000010"));
                        zb_list.add(new HomeDataBean(data.getJsSsll()==null?"-":data.getJsSsll()+"m³/h" ,"进水瞬时水量","000223238"));
                        zb_list.add(new HomeDataBean(data.getCsssll()==null?"-":data.getCsssll()+"m³/h" ,"出水瞬时水量","000112258"));
                        zb_list.add(new HomeDataBean(data.getOverCheckCount()+"/"+data.getCheckCount(),"今日工单完成"));
                        mHomeDataAdapter_zhibiao.setNewData(zb_list);
                    }
                }else{
                    ToastShow(msg);
                }


            }
        });

    }



    /**
     * ===============================================
     * 创建时间：2019/3/30 17:02
     * 编 写 人：ShenC
     * 方法说明：更新预警行动的信息
     * ================================================
     * 修改内容：      修改时间：      修改人：
     * ===============================================
     *///更新预警行动的信息
    public void RefreshReasonData() {

        //获取当前的预警行动
        String ReasonApiUrl = Config.host + WebApi.Api_GetIsRunReason;
        DataModel.GetApiRequestMode("EarlyWarningActionBean", ReasonApiUrl, new InitDataBeanBack<EarlyWarningActionBean>() {
            @Override
            public void callbak(boolean b, List<EarlyWarningActionBean> list, String msg) {
                if (b) {
                    if (list == null || list.size() == 0) {
                        home_reason_lin.setVisibility(View.GONE);
                        CacheData.Cache_WaringID = "";
                    } else {
                        home_reason_lin.setVisibility(View.VISIBLE);

                        EarlyWarningActionBean model = list.get(0);
                        CacheData.Cache_WaringID = model.getID();
                        tv_reason_name.setText(model.getName());
                        tv_reason_startdt.setText(model.getStartTime());
                        tv_reason_level.setText(model.getPrecipitation());
                        tv_solution_name.setText(model.getEmergencySolutionName());
                        tv_user_count.setText(model.getUserCount());
                        tv_car_count.setText(model.getCarCount());

                        if (!MyTextUtils.IsNullByString(model.getTaskWaterPoint()) && !MyTextUtils.IsNullByString(model.getAllWaterPoint())) {
                            tv_waterpoint_num.setText(model.getTaskWaterPoint() + "/" + model.getAllWaterPoint());
                        } else {
                            tv_waterpoint_num.setVisibility(View.GONE);
                        }

                        ls_EmergencySolutionID = model.getEmergencySolutionID();

                    }
                } else {
                    home_reason_lin.setVisibility(View.GONE);
                    ToastShow("预警行动加载错误，" + msg);
                }
            }
        });

        initReasonList();

    }

    /**
     * ===============================================
     * 创建时间：2019/3/20 16:47
     * 编 写 人：ShenC
     * 方法说明：获取预警行动数据
     * ================================================
     * 修改内容：      修改时间：      修改人：
     * ===============================================
     *///获取预警行动数据
    private void initReasonList() {
        String ApiUrl = Config.host + WebApi.Api_List_GetReasonList;
        DataModel.GetApiRequestMode("ReasonBean", ApiUrl, new InitDataBeanBack<ReasonBean>() {
            @Override
            public void callbak(boolean b, List<ReasonBean> list, String msg) {
                if (b) {
                    Config.db.deleteByWhere(ReasonBean.class, "name like '%%'");
                    for (ReasonBean model : list) {
                        //判断数据是否存在
                        List<ReasonBean> resultList = Config.db.findAllByWhere(ReasonBean.class, "ID = '" + model.getID() + "'");
                        if (resultList.size() > 0) {
                            ReasonBean mm = resultList.get(0);
                            Config.db.update(mm);
                        } else {
                            ReasonBean mm = new ReasonBean();
                            mm.setID(model.getID());
                            mm.setName(model.getName());
                            Config.db.save(mm);
                        }
                    }
                }
            }
        });
    }


    /**
     * ===============================================
     * 创建时间：2019/5/21 16:02
     * 编 写 人：ShenC
     * 方法说明：获取显示实时天气预报
     * ================================================
     * 修改内容：      修改时间：      修改人：
     * ===============================================
     *///获取显示实时天气预报
    private void initWeatherData() {

        DataModel.GetApiRequest(context, Config.SZWeatherURL, new InitDataCallBack() {
            @Override
            public void callbak(boolean b, String string) {

                if (b) {
                    try {
                        JSONObject jsondata = new JSONObject(string);


                        if (jsondata.getInt("code") == 200) {

                            JSONObject jsonroot = new JSONObject(jsondata.getString("data"));
                            JSONObject json = new JSONObject(jsonroot.getString("data"));
                            String imgurl = jsonroot.getString("imgpre") + json.getString("img");
                            String mint = json.getString("mint").split("\\.")[0];//最低温度
                            String maxt = json.getString("maxt").split("\\.")[0];//最高温度
                            String report = json.getString("report");//描述

                            String[] report_arr = report.split("；");
                            tv_home_weather_wd.setText(mint + "℃~" + maxt + "℃");
                            tv_home_weather_memo.setText("[查看详情]" + report_arr[0]);
                            FinalBitmap fb = FinalBitmap.create(context);
                            fb.display(iv_home_weather, imgurl);

                        } else {
                            ToastShow("天气获取失败," + jsondata.getString("info"));
                        }

                    } catch (Exception e) {
                        ToastShow("天气数据解析失败," + e.toString());
                    }
                } else {
                    ToastShow("天气获取失败," + string);
                }
            }
        });

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // 扫描二维码/条码回传
        if (requestCode == REQUEST_CODE_SCAN && resultCode == -1) {
            if (data != null) {
                String content = data.getStringExtra(Constant.CODED_CONTENT);
                ToastShow("结果:" + content);
            }
        }

    }

    @Override
    public void onItemClickChanged(PageGridView pageGridView, int position, HomeMenuBean bean) {

        if (bean == null) {
            return;
        }
        Intent intent;
        switch (bean.getIcon()) {
            case R.mipmap.ico_homemenu_yyd:
                intent = new Intent(context, FloodPointListActivity.class);//易淹点
                startActivity(intent);
                break;
            case R.drawable.ico_homemenu_report:

                //拿到第一个数据，判断是否是昨日数据
                String ApiUrl = Config.host
                        + WebApi.Api_GetPurificationPlantDay
                        + "GetList?limit=" + Config.PAGE_LIMIT;

                DataModel.GetApiRequestMode("PurificationPlantDayBean", ApiUrl, new InitDataBeanBack<PurificationPlantDayBean>() {
                    @Override
                    public void callbak(boolean b, List<PurificationPlantDayBean> list, String msg) {
                        if (b) {

                            if (list.size() == 0) {
                                Intent intent_report = new Intent(context, PurificationPlantDayReadActivity.class);//报表录入
                                CacheData.PurificationPlantReadDay_UPDATE = false;
                                startActivity(intent_report);
                            } else {
                                //判断第一个数据
                                PurificationPlantDayBean model = list.get(0);

                                Intent intent_report = new Intent(context, PurificationPlantDayReadActivity.class);//报表录入
                                intent_report.putExtra("ID", model.getID());
                                CacheData.PurificationPlantReadDay_UPDATE = true;
                                startActivity(intent_report);
                            }

                        } else {
                            ToastShow("打开报表失败，" + msg);
                        }
                    }
                });

                break;
            case R.mipmap.ico_homemenu_shijian:
                intent = new Intent(context, EventActivity.class);
                startActivity(intent);
                break;
            case R.mipmap.ico_homemenu_jsjc:
                intent = new Intent(context, WaterPointActivity.class);//实时积水监测
                intent.putExtra("TYPE", "NOW");
                startActivity(intent);
                break;
            case R.mipmap.ico_home_jsk:
                intent = new Intent(context, WaterPointActivity.class);//历史积水库
                intent.putExtra("TYPE", "OLD");
                startActivity(intent);
                break;
            case R.mipmap.ico_homemenu_zhjc:
                intent = new Intent(context, ComprehensiveActivity.class);//综合监测
                startActivity(intent);
                break;
            case R.mipmap.ico_homemenu_wsc:
                intent = new Intent(context, HtProcessActivity.class);//综合监测
                startActivity(intent);
                break;
            case R.mipmap.ico_homemenu_guanwang:
                intent = new Intent(context, PipeDataActivity.class);//管网
                startActivity(intent);
                break;
            default:
                ToastShow("功能正在研发中！");
                break;

        }

    }

    private void ToastShow(String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }


}
